package com.example.helloword.actuator.healthy;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.stereotype.Component;

/**
 * @ref https://segmentfault.com/a/1190000021611510
 * 程序监控:
 * 1: 添加依赖
 * management:
 *   endpoints:
 *     web:
 *       exposure:
 *         # 暴露所有的端点 通过 http://127.0.0.1:8081/actuator 进行获取
 *         include: "*"
 *   endpoint:
 *     health:
 *       # /health端点会聚合你程序的健康指标，来检查程序的健康情况。端点公开的应用健康信息取决于：
 *       show-details: always
 *
 *  2：/health 各组件的适配检查
 *  http://127.0.0.1:8081/actuator/health
 *  通过继承 AbstractHealthIndicator 函数来自定义检查
 */
@Component
@Slf4j
public class CustomHealthIndicator extends AbstractHealthIndicator {
    /**
     * 进行健康检查-如果抛出异常说明服务down了
     */
    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {
        log.info("CustomHealthIndicator doHealthCheck");
        builder.up()
                .withDetail("app", "这个项目很健康")
                .withDetail("error", "Nothing, I'm very goods");
    }
}
